package com.example.demo.controller;

import com.example.demo.api.ResponseResult;
import com.example.demo.pojo.User;
import com.example.demo.service.UserService;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.jdbc.Null;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @ClassName: HelloController
 * @Description: controller测试
 * @Author: zzz
 * @Date: 2020-04-04 20:16
 */
@Controller
public class HelloController {
    @Autowired
    private UserService userService;

    @RequestMapping(value = "/getUser",method = RequestMethod.POST)
    @ResponseBody
    @Validated
    @ApiOperation(value = "获取User信息", notes="通过User name获取信息")
    public ResponseResult<User> getUser(@RequestBody @Valid User user){
        System.out.println(user.toString());

        ResponseResult<User> responseResult=new ResponseResult();
        if(userService.GetUser(user)==null){
            responseResult.setCode(500);
            responseResult.setMsg("无数据");
        }else{
            responseResult.setCode(HttpStatus.OK.value());
            responseResult.setMsg(HttpStatus.OK.getReasonPhrase());
            responseResult.setData(userService.GetUser(user));
        }

        return responseResult;
    }

    @RequestMapping(value = "/demo",method = RequestMethod.GET)
    @ResponseBody
    public String demo( ){

        System.out.println(10/0);
        return "Demo";
    }
}
